package com.springapp.db.util;

import com.springapp.mvc.entity.Comment;
import com.springapp.mvc.entity.Post;
import com.springapp.mvc.entity.User;

import java.util.Date;

/**
 * Created by Dima on 10.01.2015.
 */
public class CommentBuilder {

    private Date dateCreated;
    private Long userId;
    private Long postId;
    private String text;

    public static CommentBuilder aComment(){
        return new CommentBuilder();
    }

    public CommentBuilder postedOn(Date dateCreated){
        this.dateCreated = dateCreated;
        return this;
    }

    public CommentBuilder withText(String text){
        this.text = text;
        return this;
    }

    public CommentBuilder fromUser(User u){
        this.userId = u.getId();
        return this;
    }

    public CommentBuilder fromUser(Long userId){
        this.userId = userId;
        return this;
    }

    public CommentBuilder forPost(Post p){
        this.postId = p.getId();
        return this;
    }

    public CommentBuilder forPost(Long postId){
        this.postId = postId;
        return this;
    }

    public Comment build(){
        Comment c = new Comment();
        c.setDateCreated(dateCreated);
        c.setUserId(userId);
        c.setCommentText(text);
        c.setPostId(postId);
        return c;
    }
}
